<?php $Gateway = config('workman.Gateway');?>
<a onclick="sendMessage()">触发</a>
<br>
<a onclick="sendRequest()">提交Request参数</a>
<br><input type="text" id="message" placeholder="发送信息">
<br><input type="text" id="f" value="/User/getUser" placeholder="默认方法">
<script>
    var ws = new WebSocket("ws://{{$Gateway['ip']}}:{{$Gateway['port']}}");
    ws.onopen = function (e) {
        console.log('Connection to server opened');
        setInterval(function () {
            ws.send(JSON.stringify({type:'ping'}));
        },5000);
    }
    function sendMessage() {
        let val = document.getElementById('message').value;
        let f = document.getElementById('f').value;
        ws.send(JSON.stringify({
            'f': f,
            val: val
        }));
    }

    function sendRequest() {
        ws.send(JSON.stringify(params));
    }


    var params = (function oneValues() {
        var query = location.search.substr(1)
        query = query.split('&')
        var params = {}
        for (let i = 0; i < query.length; i++) {
            let q = query[i].split('=')
            if (q.length === 2) {
                params[q[0]] = q[1]
            }
        }
        return params  //返回?号后面的参数名与参数值的数组
    }());
</script>
